package gui;

import dataconnect.SqlConnection;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;

/**
 * description: Earnings
 * 盈利页面
 * @author what-is-me
 * @date 2022/1/3 23:26
 */
public class Earnings extends GridBagPanel {
    public static DefaultTableModel tModel;
    static SqlConnection sql;

    public Earnings(SqlConnection sql) {
        /**
         * Description: Earnings
         * @param sql:dataconnect.SqlConnection
         * @return {@link null}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:26
         */
        Earnings.sql = sql;
        tModel = new DefaultTableModel();
        JTable table = new JTable(tModel);
        table.setFont(new Font("宋体", Font.PLAIN, 16));
        table.setRowHeight(20);
        table.getTableHeader().setFont(new Font("宋体", Font.PLAIN, 16));
        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane, 0, 0, 1, 1, 1, 0);
        update();
    }

    public static void update() {
        /**
         * Description: update
         * 更新表格
         * @param :
         * @return
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:27
         */
        String[][] row = sql.inv.queryEarning();
        String[] tg = { "项目名", "所投单位", "投资开始日期", "预期结束日期", "投资金额($)", "收益($)" };
        tModel.setDataVector(row, tg);
    }
}